//
//  Header.h
//  DiceWar
//
//  Created by xiaofeng on 20/6/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#ifndef CLASS_GAME_UTIL_RANDOMGENERATOR_H_
#define CLASS_GAME_UTIL_RANDOMGENERATOR_H_

#include <vector>

class RandomGenerator
{
public:
    RandomGenerator();
    ~RandomGenerator();
    
    
    /** to shuffle the numbers in the vector
     */
    void shuffle(std::vector<int>& values);
    
    /** get a random number within range [0, upper);
     */
    int getRandomNum(int upper);
    
    /** get a random number within range [lower, upper);
     */
    int getRandomNum(int lower, int upper);
    
    /** randomly seperate a positive number into numSegmenets segments, for example: 
     number = 20, numSegments = 3; then output can be 6, 3, 11 
     param number: in
     param numSegments: in
     param segments: out
     */
    void getRandomSegments(int number, int numSegements, std::vector<int>& segments);

    /** param number: in
     param numSegments: in
     param segments: in/out
     */
    void getRandomSegmentsWithPreAllocation(int number, int numSegements, std::vector<int>& segments);
    
    /** randomly seperate a positive number into numSegmenets segments, and make sure each segment is in [segmentLower, segmentUpper]
     number = 20, numSegments = 3; then output can be 6, 3, 11 
     param number: in
     param numSegments: in
     param segmentLower: in
     param segmentUpper: in
     param segments: out
     */
    void getRandomSegments(int number, int numSegements, int segmentLower, int segmentUpper, std::vector<int>& segments);
    
    /** param number: in
     param numSegments: in
     param segmentLower: in
     param segmentUpper: in
     param segments: in/out
     */
    void getRandomSegmentsWithPreAllocation(int number, int numSegements, int segmentLower, int segmentUpper, std::vector<int>& segments);
};

#endif //CLASS_GAME_UTIL_RANDOMGENERATOR_H_
